"use strict";
cc._RF.push(module, 'fcead9mmDpOX7oFp0X939KQ', 'TopUi');
// Script/TopUi.ts

"use strict";
/**
 * 左上角 体力 金币
 */
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var addEngry_1 = require("./addEngry");
var addGold_1 = require("./addGold");
var Define_1 = require("./SdkTools/Define");
var gamePrefabMgr_1 = require("./SdkTools/gamePrefabMgr");
var gameStorage_1 = require("./SdkTools/gameStorage");
var storage_1 = require("./SdkTools/storage");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var TopUi = /** @class */ (function (_super) {
    __extends(TopUi, _super);
    function TopUi() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.tilistr = null;
        _this.timestr = null;
        _this.goldstr = null;
        _this.runtime = 0; //0 满1亏
        return _this;
    }
    // LIFE-CYCLE CALLBACKS:
    // @property(cc.Prefab)
    // addtiliprefab:cc.Prefab = null
    // @property(cc.Prefab)
    // addgoldprefab:cc.Prefab = null
    TopUi.prototype.onLoad = function () {
        this.setGold();
        this.setTiLi();
        var addengrybtn = cc.find('tili', this.node);
        addengrybtn.on('click', this.openAddEngry, this);
        var addgoldbtn = cc.find('gold', this.node);
        addgoldbtn.on('click', this.openAddGold, this);
        gameStorage_1.default.setoffLineTime();
    };
    TopUi.prototype.start = function () {
    };
    TopUi.prototype.openAddEngry = function () {
        var newnode = cc.instantiate(gamePrefabMgr_1.default.Instance.uiPre[gamePrefabMgr_1.uiPreName.addEngry]);
        newnode.parent = cc.director.getScene();
        var sc = newnode.getComponent(addEngry_1.default);
        sc.setTopUiSc();
        console.log('ddddddddd');
        // let newnode = cc.instantiate(gamePrefabMgr.Instance.uiPre[uiPreName.addEngry])
        // newnode.parent = cc.director.getScene()
        // console.log('3333333',newnode)
        // console.log('打印脚本', newnode.getComponent(addEngry))
        // let sc = newnode.getComponent(addEngry)
        // console.log('4444444', sc)
        // sc.setTopUiSc()
        // console.log('5555555')
    };
    TopUi.prototype.openAddGold = function () {
        var newnode = cc.instantiate(gamePrefabMgr_1.default.Instance.uiPre[gamePrefabMgr_1.uiPreName.addGold]);
        newnode.parent = cc.director.getScene();
        var sc = newnode.getComponent(addGold_1.default);
        sc.setTopUiSc();
    };
    /**
     * 设置gold
     */
    TopUi.prototype.setGold = function () {
        this.goldstr.string = '' + storage_1.default.Instance.getGold();
    };
    /**
     * 设置体力
     */
    TopUi.prototype.setTiLi = function () {
        //console.log('体力',storage.Instance.getEnergy())
        this.tilistr.string = '' + storage_1.default.Instance.getEnergy();
    };
    TopUi.prototype.addEneryTime = function () {
        var self = this;
        this.schedule(function () {
            storage_1.default.Instance.eneryTime--;
            self.timestr.string = '' + self.secondsFormat(storage_1.default.Instance.eneryTime);
            //console.log('倒计时', gameConfig.eneryTime,self.timeFormat(gameConfig.eneryTime)  )
            if (storage_1.default.Instance.eneryTime <= 0) {
                storage_1.default.Instance.eneryTime = Define_1.default.eneryTime;
                self.unscheduleAllCallbacks();
                storage_1.default.Instance.setEnergy(storage_1.default.Instance.getEnergy() + 1);
                self.setTiLi();
                self.runtime = 0;
                self.timestr.string = '00:00';
            }
        }, 1, 3000, 0);
    };
    /**
     * 数字转时间格式
     * @param sec
     * @returns
     */
    TopUi.prototype.secondsFormat = function (sec) {
        var hour = Math.floor(sec / 3600);
        var minute = Math.floor((sec - hour * 3600) / 60);
        var second = sec - hour * 3600 - minute * 60;
        var hour1 = '';
        var minute1 = '';
        var second1 = '';
        if (hour < 10) {
            hour1 = "0" + hour;
        }
        if (minute < 10) {
            minute1 = "0" + minute;
        }
        else {
            minute1 = "" + minute;
        }
        if (second < 10) {
            second1 = "0" + second;
        }
        else {
            second1 = "" + second;
        }
        //return hour + ":" + minute + ":" + second;
        return minute1 + ":" + second1;
    };
    TopUi.prototype.update = function (dt) {
        if (storage_1.default.Instance.nowEnery >= Define_1.default.maxEnery && this.timestr.string != '已满') {
            console.log('-------------');
            this.unscheduleAllCallbacks();
            this.runtime = 0;
            this.timestr.string = '已满';
            storage_1.default.Instance.eneryTime = Define_1.default.eneryTime;
        }
        if (this.runtime == 1)
            return;
        if (storage_1.default.Instance.nowEnery < Define_1.default.maxEnery) {
            this.runtime = 1;
            this.addEneryTime();
        }
    };
    TopUi.prototype.cutSchedule = function () {
        this.unscheduleAllCallbacks();
    };
    __decorate([
        property(cc.Label)
    ], TopUi.prototype, "tilistr", void 0);
    __decorate([
        property(cc.Label)
    ], TopUi.prototype, "timestr", void 0);
    __decorate([
        property(cc.Label)
    ], TopUi.prototype, "goldstr", void 0);
    TopUi = __decorate([
        ccclass
    ], TopUi);
    return TopUi;
}(cc.Component));
exports.default = TopUi;

cc._RF.pop();